package com.cooriproject.basemanage.service.serviceImpl;

import com.cooriproject.basemanage.entity.ItemInfo;
import com.cooriproject.basemanage.entity.User;
import com.cooriproject.basemanage.mapper.ItemMapper;
import com.cooriproject.basemanage.mapper.UserMapper;
import com.cooriproject.basemanage.service.ItemService;
import com.cooriproject.basemanage.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {

    @Resource
    private ItemMapper itemmapper;
    @Resource
    private UserMapper usermapper;
    @Override
    public int itemInsertApplicant(String itemCode, String itemName, Integer itemMinNum, String itemBrand, String itemModel, String itemSpecifications, Integer itemType, Integer itemDisaudit, Integer itemApplicantUserId, Integer itemCon) {
        return itemmapper.itemInsertApplicant(itemCode, itemName, itemMinNum, itemBrand, itemModel, itemSpecifications, itemType, itemDisaudit, itemApplicantUserId, itemCon);
    }

    @Override
    public List<ItemInfo> selectByPrimaryKey(Integer itemId) {
        return itemmapper.selectByPrimaryKey(itemId);
    }

    @Override
    public int deleteByPrimaryKey(Integer itemId, Integer userId) {
        List<User> list = usermapper.selectAllByUserId(userId);
        if (list.get(0).getUserType()==1){
            return itemmapper.deleteByPrimaryKey(itemId);
        }else {
            return -1;
        }
    }

    @Override
    public int updateByPrimaryKeySelective(Integer itemId,Integer userId,String itemCode, String itemName, Integer itemMinNum, String itemBrand, String itemModel, String itemSpecifications, Integer itemType, Integer itemDisaudit, Integer itemApplicantUserId, Integer itemApproverStatus,Integer itemApproverUserId,Integer itemUpdatedUserId, String itemCreatedTime,String itemUpdatedTime,Integer itemCon) {
        List<User> list = usermapper.selectAllByUserId(userId);
        if (list.get(0).getUserType()==1){
            return itemmapper.updateByPrimaryKeySelective(itemId, userId, itemCode, itemName, itemMinNum, itemBrand, itemModel, itemSpecifications, itemType, itemDisaudit, itemApplicantUserId, itemApproverStatus, itemApproverUserId, itemUpdatedUserId, itemCreatedTime, itemUpdatedTime, itemCon);
        }else {
            return -1;
        }
    }

    @Override
    public List<ItemInfo> selectAll() {
        return itemmapper.selectAll();
    }
}
